package com.ly.ThreadExit;

public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.setName("张三");
        t.setPriority(Thread.MIN_PRIORITY);
        t.start();

        System.out.println(t.getName());
        //主线程打印5个hi,然后我就中断子线程的休眠
        for (int i = 0; i < 5; i++) {
            Thread.sleep(1000);
            System.out.println("hi"+i);
        }
        //中断 T线程休眠，提前结束休眠
        System.out.println(t.getName()+"线程的优先䤸"+t.getPriority());
        t.interrupt();

    }
}
class T extends Thread{
    @Override
    public void run() {
        while (true){
            for (int i = 0; i <100; i++) {
                System.out.println("线程名"+Thread.currentThread().getName()+"吃包子"+i);
            }
            try {
                System.out.println("休息中");
                Thread.sleep(20000);
            } catch (InterruptedException e) {
                System.out.println("线程名"+Thread.currentThread().getName()+"被interrupt");
            }
        }
    }
}
